 /**
 * <p>Title: EllipseArray</p>
 * Description: CS 235 Assignment 2 
 * 	    Contains the methods to create Ellipse Array and store major and minor axes inside each array
 * @author JGroup 7: Nicholas A. Peterson, Dan Prayfrock, Tyler Rasmussen, John Feia
 * @date   Nov 4th 2011
 */
package a2;
/**
 * Create a new Ellipse Array.
 * 
 */

public class EllipseArray {
	//initialized variables
	private Ellipse[] store;																				//Ellipse[] Data type called store;
	private int HistorySize;																				//int value for Ellipse size
	private int topEllipse;																					//int value to for returning values
	
	/**
	 * Default constructor Ellipse Array.
	 * 
	 */
	//EllipseArray Constructor
	public EllipseArray() {
	}
	
	
	
	/**
	 * Create a new Ellipse Array with the specified size
	 * each index will have a major and minor axes.
	 * The axes must be non-negative.
	
	 */
	//EllipseArray Constructor
	public EllipseArray(int size) {
																		
		HistorySize=size;																					//EllipseArray size
		topEllipse=0;																						//EllipsArray [Starts at index 0]
		store = new Ellipse[HistorySize];																	//New Ellipse
	}
	
	/**
	 * Adds a Ellipse with the specified major and minor axes to a New Location.
	 * The axes must be non-negative.
	 * @Require (new Ellipse(major, minor) && (major_axis > 0 && minor_axis > 0));
	 * @Ensure  Add new Ellipse to EllipseArray;
	 */
	//Add to Ellipse
	public void AddEllipse(Ellipse ell){	
		int i=0;																							//Loop variable
		boolean done=false;																					// Boolean to determine if EllipseArray has been created
		while((i<HistorySize)&&(done==false)){																//If no value in index 0, index is filled with first Ellipse
			if (store[i]==null){																				
				store[i] = ell;
				topEllipse=i;
				done=true;																					//Boolean = already create EllipseArray
			}
			else if(i+1==HistorySize){																		//If index 0 has value, add index [i+1]
				slideArray();																				//Slide down each Element one index
				store[i]=ell;																				//store null index with current Ellipse
				topEllipse=i;																		
				done=true;
			}
			i++;																					
		}
	}
	
	
	/**
	 * Get Ellipse.
	 */
	
	//Get value
	public Ellipse get() {	
		return store[topEllipse];																			//Return Ellipse Last Value
	}
	
	/**
	 * Slides each store[index] to the previous spot in the EllipseArray
	 * @requires store[]=new store[2];
	 * @ensures store[0] = oldObj && store[1] = oldObj -->store[0] = newOBj store[1] = newObj;
	 */
	
	//Move value
	private void slideArray(){
		
		for(int i=1;i<HistorySize;i++){																		//Takes the new Ellipse and stores in the Last position of the Ellipse Array
			store[i-1]=store[i];																			// and Shifts all other Elements in the EllipseArray to the previous index
		}
	}
	
	
	/**
	 * To String Method for OutPut
	 */
	//Print value to display
	public String toString(){
		String data="";																						//to string method variable
		for (int i=0;i<HistorySize;i++){
			if(store[i]!=null){
				data+= ""+i+"\tMjr Axis: "+store[i].majorAxis()+
						" \n\tMnr Axis: " +store[i].minor_axis()+
						" \n\tArea: " +store[i].area()+
						" \n\tCircumference: " +store[i].circumference()+"\n";
			}
		}
		return data;
	}
}
